# -*- coding:utf-8 -*-
from infrastructure.utils.result import R
from interface.interface_base import app, request, jsonify
from service.groupRiseViewService import groupRotationPointView
from service.groupRotationViewService import groupViewMain
from service.groupService import groupRotation, groupTopStatistics
from infrastructure.utils.log import logger


@app.route('/group/save', methods=['POST'])
def save_group():
    dti = None
    if 'dti' in request.args:
        dti = request.args.get('dti')
    groupRotation(dti)
    return jsonify(R.success().__dict__)


@app.route('/group/updateGroupTop', methods=['POST'])
def updateGroupTop():
    ds = request.json
    if ds is None or len(ds) == 0:
        return jsonify(R.fail(msg="请输入需要操作的日期列表").__dict__)
    for d in ds:
        groupTopStatistics(d)
    return jsonify(R.success().__dict__)


@app.route('/group/report', methods=['POST'])
def groupReport():
    groupViewMain()
    return jsonify(R.success().__dict__)


@app.route('/group/detailReport', methods=['POST'])
def groupDetailReport():
    d = request.json
    groupIds = None
    if 'groupIds' in d:
        groupIds = d['groupIds']
        if groupIds is None or len(groupIds) == 0:
            return jsonify(R.error(msg="没有指定参数").__dict__)
    groupRotationPointView(groupIds)
    return jsonify(R.success().__dict__)
